<?php
class Test_Event_Log_Message_Stub_Message extends \Event\Log\Message {
	const FORMAT = '%s & %s = %s';
}
class Test_Event_Log_Message extends PHPUnit_Framework_TestCase {
	protected function getStringPrefix(){
		return date('Y-m-d ').'[0-2][0-9]:[0-5][0-9]:[0-5][0-9] - '.(isset($_SERVER['REMOTE_ADDR'])? $_SERVER['REMOTE_ADDR']:'unknown IP').' ';
	}
	public function testTwoArgsDefaultInformation(){
		$sPrefix = $this->getStringPrefix();
		foreach (array(
			array('cool stuff', 'really cool'),
			array('ç\'est', 'tres €!')
		) as $asMessage){
			$sExpectation = vsprintf(\Event\Log\Message::FORMAT, $asMessage);
			$this->assertEquals(
				1,
				preg_match(
					'~^'.$sPrefix.str_replace(array('[', ']'), array('\[', '\]'), $sExpectation).'$~',
					(string) new \Event\Log\Message($asMessage[0], $asMessage[1])
				),
				'unexpected message ('.$sExpectation.')'
			);
		}
	}
	public function testExtensionWithOwnFormatAndMoreArguments(){
		foreach (array(
			array('cool stuff', 'unimaginative', 'really cool'),
			array('ç\'est', 'hip hip: hurray!', 'trés €!')
		) as $asMessage){
			$sExpectation = vsprintf(Test_Event_Log_Message_Stub_Message::FORMAT, $asMessage);
			$this->assertEquals(
				1,
				preg_match(
					'~'.$sExpectation.'$~',
					(string) new Test_Event_Log_Message_Stub_Message($asMessage[0], $asMessage[1], $asMessage[2])
				),
				'unexpected message ('.$sExpectation.') value with more params'
			);
		}
	}
}